#include "libLUI_in.h"

struct LUIControl *LUICreateControl( struct LUIWindow *window , struct LUIRectangle control_relative_rect , int styles , int properties , int control_type , void *data , funcLUIDrawControlProc *pfuncLUIDrawControlProc )
{
	struct LUIControl	*control = NULL ;
	
	control = (struct LUIControl *)malloc( sizeof(struct LUIControl) ) ;
	if( control == NULL )
		return NULL;
	memset( control , 0x00 , sizeof(struct LUIControl) );
	
	control->window = window ;
	
	memcpy( & (control->control_relative_rect) , & control_relative_rect , sizeof(struct LUIRectangle) );
	memcpy( & (control->control_bright_edge_color) , & (window->windows_manager->control_bright_edge_color_default) , sizeof(struct RBGA) );
	memcpy( & (control->control_dark_edge_color) , & (window->windows_manager->control_dark_edge_color_default) , sizeof(struct RBGA) );
	memcpy( & (control->control_bg_color) , & (window->windows_manager->control_bg_color_default) , sizeof(struct RBGA) );
	memcpy( & (control->control_font_color) , & (window->windows_manager->control_font_color_default) , sizeof(struct RBGA) );
	control->styles = styles ;
	control->properties = properties ;
	control->control_type = control_type ;
	control->data = data ;
	control->pfuncLUIDrawControlProc = pfuncLUIDrawControlProc ;
	
	list_add_tail( & (control->this_listnode) , & (window->controls_list.this_listnode) );
	
	if( window->p_focus_control == NULL )
		window->p_focus_control = control ;
	
	return control;
}

int LUIDestroyControl( struct LUIControl *control )
{
	list_del( & (control->this_listnode) );
	
	free( control );
	
	return 0;
}

void LUISetControlBgColor( struct LUIControl *control , struct RBGA *p_color )
{
	memcpy( & (control->control_bg_color) , p_color , sizeof(struct RBGA) );
	return;
}

void LUISetControlFontColor( struct LUIControl *control , struct RBGA *p_color )
{
	memcpy( & (control->control_font_color) , p_color , sizeof(struct RBGA) );
	return;
}

void LUISetDrawControlProc( struct LUIControl *control , funcLUIDrawControlProc *pfuncLUIDrawControlProc )
{
	control->pfuncLUIDrawControlProc = pfuncLUIDrawControlProc ;
	return;
}

void LUISetControlEventProc( struct LUIControl *control , funcLUIControlEventProc *pfuncLUIControlEventProc )
{
	control->pfuncLUIControlEventProc = pfuncLUIControlEventProc ;
	return;
}

int LUIGetControlStyles( struct LUIControl *control )
{
	return control->styles;
}

int LUIGetControlProperties( struct LUIControl *control )
{
	return control->properties;
}

int LUIGetControlType( struct LUIControl *control )
{
	return control->control_type;
}

void LUISetControlData( struct LUIControl *control , void *data )
{
	control->data = data ;
	return;
}

void *LUIGetControlData( struct LUIControl *control )
{
	return control->data;
}

struct LUIWindow *LUIGetWindowOfControl( struct LUIControl *control )
{
	return control->window;
}

